﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;

public static class ImageExtensionMethods
{
    public static byte[] ToByteArrayJpeg(this Image img)
    {
        if (img == null)
            throw new ArgumentNullException("this is null");

        // continue
        using (var ms = new MemoryStream())
        {
            img.Save(ms, ImageFormat.Jpeg);

            ms.Flush();

            return ms.ToArray();
        }
    }
}
